<%-- 
    Document   : lab
    Created on : 2019-2-17, 16:53:57
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    session.setAttribute("url", "../roster/roster.jsp");
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>        
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/color.css" type="text/css" />
        <link rel="stylesheet" href="../../css/demo.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>
        <script type="text/javascript">

            $(document).ready(function() {
                $('#dgstudent').datagrid({
                    height: ($(window).height() - 40) + 'px'                    
                });               
                
            });


        </script>
    </head>
    <body>
        <script type="text/javascript">
            var url;
            var teachclassid = <%=session.getAttribute("teachclassid")%>
            var courseName = '<%=session.getAttribute("courseName")%>';

            function newStudent() {
                var dd = $('#dgstudent').datagrid('getData')
                $('#dlg').dialog('open').dialog('setTitle', '新学生');
                $('#fm').form('clear');
                $('#no').val(dd.total + 1);
                //$('#studentno1').textbox('readonly',false);
                
                url = '../../servlet/roster/SaveRosterServlet';
            }

            function resetPassword() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('提示', '您确定重置该学生密码吗？', function(r) {
                        if (r) {
                            $.post('../../servlet/roster/ResetPassword',
                                    {studentno: row.studentno}, function(result) {
                                if (result.success) {
                                    $.messager.show({// show error message
                                        title: '提示',
                                        msg: '重置成功'
                                    });
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
            function excelImport() {
                $.messager.alert('提示', '该功能等待实现', 'info');
            }
            function destroyStudent() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('提示', '您确定要删除该学生信息吗? 同时将删除与该学生相关的实验、作业、考勤等信息。', function(r) {
                        if (r) {
                            $.post('../../servlet/roster/DestroyRosterServlet',
                                    {studentno: row.studentno, teachclassid: teachclassid}, function(result) {
                                if (result.success) {
                                    $('#dgstudent').datagrid('reload');    // reload the user data
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
            //清除所有学生，可以安装平时成绩记录表重新整理学生次序，但是删除学生会删除与学生相关的实验，作业等相关信息
            /*function clearStudents() {
             var row = $('#dgstudent').datagrid('getSelected');
             if (row) {
             $.messager.confirm('提示', '您确定要删除该学生信息吗? 同时将删除与该学生相关的实验、作业、考勤等信息。', function(r) {
             if (r) {
             $.post('../../servlet/roster/DestroyRosterServlet', 
             {studentno: row.studentno,teachclassid:teachclassid}, function(result) {
             if (result.success) {
             $('#dgstudent').datagrid('reload');    // reload the user data
             } else {
             $.messager.show({// show error message
             title: 'Error',
             msg: result.errorMsg
             });
             }
             }, 'json');
             }
             });
             }
             }*/
            function editStudent() {
                var row = $('#dgstudent').datagrid('getSelected');
                if (row) {
                    $('#dlg').dialog('open').dialog('setTitle', '编辑');
                    $('#fm').form('load', row);
                    $('#studentno1').textbox('readonly', true);
                    url = '../../servlet/roster/EditRosterServlet';
                }
            }
            function refreshStudent() {
                $('#dgstudent').datagrid('reload');    // reload the user data
            }
            function saveStudent() {
                //alert(url);
                $('#fm').form('submit', {
                    url: url,
                    onSubmit: function() {
                        return $(this).form('validate');
                    },
                    success: function(result) {
                        var result = eval('(' + result + ')');
                        if (result.errorMsg) {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        } else {
                            $('#dlg').dialog('close');        // close the dialog
                            $('#dgstudent').datagrid('reload');    // reload the user data
                        }
                    }
                });
            }
        </script>
        <table id="dgstudent" title="学生名单管理" class="easyui-datagrid"
               url="../../servlet/roster/GetRosterServlet"
               toolbar="#toolbar"
               rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                <tr>                    
                    <th field="no" width="50">序号</th>
                    <th field="studentno" width="120">学号</th>
                    <th field="name" width="80">姓名</th>                    
                    <th field="pinyin" width="120">拼音</th>                    
                    <th field="note" width="50">备注</th>

                </tr>
            </thead>
        </table>
        <div id="toolbar">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newStudent()">增加</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editStudent()">修改</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyStudent()">删除</a>
            <!--<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="clearStudents()">清除</a>-->
            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="refreshStudent()">刷新</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-reset" plain="true" onclick="resetPassword()">重置密码</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-reset" plain="true" onclick="excelImport()">Excel导入</a>
        </div>
        <div id="dlg" class="easyui-dialog" style="width:500px;height:320px;padding:5px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">学生信息</div>
            <form id="fm" method="post">                

                <div class="fitem" >
                    <label>学号:</label>
                    <input id="studentno1"  class="easyui-textbox" name="studentno"  required="true">
                </div>
                <div class="fitem">
                    <label>姓名:</label>
                    <input id="name" name="name" class="easyui-textbox"   required="required">
                </div>                
                <div class="fitem">
                    <label>序号:</label>
                    <input id="no" name="no" class="easyui-validatebox" required="true" >
                </div>
                <div class="fitem">
                    <label>备注:</label>
                    <input name="note" >
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveStudent()">保存</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>
        <style type="text/css">
            #fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:5px;
            }
            .fitem label{
                display:inline-block;
                width:80px;
            }
            .fitem input{
                width:160px;
            }
        </style>
    </body>
</html>
